/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import DAO.OptionDAO;
import DTO.OptionDTO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author dienvm60347
 */
public class OptionDAO {
    public static List getOption(){
       Connection con = null;
       PreparedStatement stm = null;
       ResultSet rs = null;
       List optionlist = new ArrayList();
        try {
            
            con= connectData.makeConnect();
            String sql = "select * from tbl_OptionType";
            stm = con.prepareStatement(sql);
            rs = stm.executeQuery();
            while(rs.next()){
                
                int id = Integer.parseInt(rs.getString("OptionID"));
                String name = rs.getString("OptionName");
                String type = rs.getString("OptionType");
                OptionDTO option = new OptionDTO(id, name, type);
                optionlist.add(option);
            }
            return optionlist;
        } catch (SQLException e) {
            System.out.println(e);
        }finally{
            try {
                if(stm!=null){
                    stm.close();
                }
                if(rs!=null){
                    rs.close();
                }
                if(con!=null){
                    con.close();
                }
            } catch (SQLException ex) {
                Logger.getLogger(AccountDAO.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return null;
    }
}
